export default {
  data () {
    return {
      touchData: {
        startX: '',
        startY: '',
        endX: '',
        endY: '',
        isMove: 0
      }

    }
  },
  methods: {
    /***
     * 误按操作识别
     */
    touchstart (e) {
      this.touchData.timeStamp = e.timeStamp
      this.touchData.startX = e.clientX
      this.touchData.startY = e.clientY
    },
    touchend (e) {
      this.comTouchDirection(this.touchData)
    },
    touchmove (e) {
      this.touchData.isMove = true
      this.touchData.endX = e.clientX
      this.touchData.endY = e.clientY
    },
    comTouchDirection (touchData) {
      let xChange = Math.abs(touchData.startX - touchData.endX)
      let yChange = Math.abs(touchData.startY - touchData.endY)

      if (!touchData.isMove) {
        return
      }
      touchData.isMove = false
      if (xChange > yChange) {
        // 左右滑动
        if (touchData.startX < touchData.endX) {
          this.move(2)
        } else {
          this.move(4)
        }
      } else {
        // 上下滑动
        if (touchData.startY < touchData.endY) {
          this.move(3)
        } else {
          this.move(1)
        }
      }
    }
  }
}
